﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.ServiceLocation;

namespace MShop.Web.Components.ModelBinders
{
   
    public class BindUsingAttribute:System.Web.Mvc.CustomModelBinderAttribute
    {
        private readonly Type binderType;
        public BindUsingAttribute(Type type)
        {
            if(!typeof(IModelBinder).IsAssignableFrom(type))
            {
                throw new InvalidOperationException();
            }
            binderType= type;
        }

        public override System.Web.Mvc.IModelBinder GetBinder()
        {
               var binder= (IModelBinder)ServiceLocator.Current.GetInstance(binderType);
               return binder;
        }

        public bool Fetch { get; set; }

    }
}